﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entitty;

namespace ClassLibrary.DAO
{
     public class TblNoiDungDAO
    {
         private DBService _db = null;
         public TblNoiDungDAO(string ConnectionString)
         {
            _db = new DBService(ConnectionString);
         }
         public DataTable Insert(TblNoiDung noidung, int Mode)
         {
              DataTable dt = null;
              try
              {

                  dt = _db.ExeSP_DataTable("sp_NoiDung_InsUp",
                      new string[] { "@id", "@Noidung", "@IDLang", "@IDMenu", "@mode" },
                      new object[] {noidung.IdNoidung, noidung.Noidung, noidung.IDLang, noidung.IDMenu, Mode},
                      CommandType.StoredProcedure); 
              }
              catch (Exception ex)
              {
                  throw ex;
              }
              return dt;
         }

         public TblNoiDung GetNoiDung_ByID(int id, int IDLang)
         {
             TblNoiDung noidung = new TblNoiDung();
             try
             {
                 DataTable dt = null;
                 dt = _db.ExeSP_DataTable("sp_GetNoiDungTieuDe",
                     new string[] { "@idNoidung", "@IDLang" },
                     new object[] { id, IDLang }, CommandType.StoredProcedure);

                 foreach (DataRow dr in dt.Rows)
                 {
                     noidung.IDLang = IDLang;
                     noidung.IdNoidung = id;
                     noidung.Noidung = dr["Noidung"].ToString();
                     noidung.IDMenu = Convert.ToInt32(dr["ID"].ToString());
                 }

             }
             catch (Exception ex)
             {
                 throw ex;
             }

             return noidung;
         }


         public DataTable getTieuDe_ByID(int id, int idLang)
         {
             DataTable dt = null;
             try
             {
                 dt = _db.ExeSP_DataTable("sp_GetNoiDungTieuDe",
                     new string[] { "@idNoidung", "@IDLang" },
                     new object[] { id, idLang }, CommandType.StoredProcedure);
             }
             catch (Exception ex)
             {
                 throw ex;
             }
             return dt;
         }
         public DataTable GetAllTieuDe()
         {
             DataTable dt = null;
             try
             {
                 dt = _db.ExeSP_DataTable("select a.idNoidung, a.ID, a.IDLang, a.Noidung, b.MenuName from TblNoiDung a, TblMenu b where a.ID = b.ID", false, CommandType.Text);
             }
             catch (Exception ex)
             {
                 throw ex;
             }

             return dt;
         }
      

    }
}
